package com.lemon.smartsafetynew.ui.fragment.record;

import android.os.Bundle;
import android.view.View;

import com.lemon.android.http.LemonRequestParams;
import com.lemon.smartsafety.R;
import com.lemon.smartsafety.app.RefreshType;
import com.lemon.smartsafety.listener.RecycleChildItemClickListener;
import com.lemon.smartsafetynew.ui.activity.record.RecordHighDangerDetailActivity;
import com.lemon.smartsafetynew.ui.fragment.base.BasePullToRefreshAddTitleFragment;
import com.lemon.smartsafety.utils.app.UIHelper;
import com.lemon.smartsafetynew.entity.electrical.ElectricalCompanyVo;
import com.lemon.smartsafetynew.entity.highDanger.HighDangerItemVo;
import com.lemon.smartsafetynew.entity.me.MeCompanyVo;
import com.lemon.smartsafetynew.net.services.RecordServices;
import com.lemon.smartsafetynew.ui.activity.highDanger.HighDangerListActivity;
import com.lemon.smartsafetynew.ui.adapter.record.HighDangerAdapter;
import com.lemon.smartsafetynew.util.constants.KeyConstants;

import java.util.List;

import kale.adapter.LemonRcvAdapter;

/**
 * 高位工艺
 * Created by Andrew on 2018/3/19.
 */

public class RecordHighDangerFragment extends BasePullToRefreshAddTitleFragment<HighDangerItemVo, List<HighDangerItemVo>>
        implements RecycleChildItemClickListener<HighDangerItemVo> {

    private static MeCompanyVo companyVo;

    @Override
    protected void initViews() {
        super.initViews();
        llTilte.setVisibility(View.VISIBLE);
        tvTitle.setText(R.string.company_space_count);
    }

    @Override
    protected void getBaseArguments() {
        super.getBaseArguments();

        Bundle bundle = getArguments();
        if (bundle != null) {
            if (bundle.containsKey(KeyConstants.KEY_COMPANY_VO)) {
                companyVo = (MeCompanyVo) bundle.getSerializable(KeyConstants.KEY_COMPANY_VO);
            }
        }

    }

    public static RecordHighDangerFragment newInstance(MeCompanyVo companyVo) {

        Bundle args = new Bundle();
        args.putSerializable(KeyConstants.KEY_COMPANY_VO, companyVo);

        RecordHighDangerFragment fragment = new RecordHighDangerFragment();
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void onLoadMore() {
        LemonRequestParams params = new LemonRequestParams("");
        params.put("company_id", companyVo.getCompany_id());
        params.put("pageNum", currentPage);
        params.put("pageSize", pageSize);
        RecordServices.init().getHighDangerInfoList(RefreshType.LOAD_MORE, params);
    }

    @Override
    public void onPullRefresh() {
        LemonRequestParams params = new LemonRequestParams("");
        params.put("company_id", companyVo.getCompany_id());
        params.put("pageNum", currentPage);
        params.put("pageSize", pageSize);
        RecordServices.init().getHighDangerInfoList(RefreshType.REFRESH, params);
    }

    @Override
    public void onChildItemClick(HighDangerItemVo data, int position) {
        ElectricalCompanyVo electricalCompanyVo = new ElectricalCompanyVo();
        electricalCompanyVo.setCompanyId(companyVo.getCompany_id());
        Bundle bundle = new Bundle();
        bundle.putSerializable(KeyConstants.KEY_ELECTRICAL_COMPANY_INFO, electricalCompanyVo);
        UIHelper.showActivity(getmContext(), bundle, HighDangerListActivity.class);
    }

    @Override
    public void onItemClick(HighDangerItemVo data, int position) {
        Bundle bundle = new Bundle();
        bundle.putSerializable(KeyConstants.KEY_HIGH_DANDER_VO, data);
        bundle.putBoolean("isShowReturn",companyVo.getIfShowReturn());
        UIHelper.showActivity(getmContext(), bundle, RecordHighDangerDetailActivity.class);
    }

    @Override
    public boolean goRefreshOnCreate() {
        return true;
    }

    @Override
    public LemonRcvAdapter<HighDangerItemVo> getLemonAdapter() {
        return new HighDangerAdapter(mDataList, this);
    }

    @Override
    public String getHttpTag() {
        return KeyConstants.URL_COMPANY_INFO_HIGH_DANGER_LIST;
    }

    @Override
    public void onDataList(List<HighDangerItemVo> data) {
        if(data != null && data.size() > 0) {
            tvTitleCount.setText("" + data.get(0).getCount());
        }else{
            tvTitleCount.setText("0");
        }
    }

}
